# -*- coding=UTF-8 -*-
# @Project          WeChatPublicNumberPushInformation
# @fileName         tian_api.py
# @author           Echo
# @EditTime         2024/9/10
from typing import Text, Optional, List, Dict

import httpx

from common import config


class TianApi:
    def __init__(self):
        self.api_key = config.get("tian_api_key")
        self.client = httpx.Client(base_url="https://apis.tianapi.com")

    def get_rainbowFart(self):
        """
        获取彩虹屁
        :return: 
        """
        response = self.client.get(
            url=f"/caihongpi/index?key={self.api_key}"
        ).json()
        if response.get("msg") == "success":
            return response["result"]["content"]

    def get_horoscope(self, star_sign: Text, date: Optional[Text] = None) -> List:
        """
        获取星座运势
        :param star_sign: 星座名（必填）
        :param date: 出生日期（可选）
        :return: 
        """
        if date is None:
            url = f"/star/index?key={self.api_key}&astro={star_sign}"
        else:
            url = f"/star/index?key={self.api_key}&astro={star_sign}&date={date}"
        response = self.client.get(
            url=url
        ).json()
        return response["result"]["list"]

    def get_weather_infos(self, city: Text) -> Dict:
        """
        获取天气
        :param city: 城市（城市天气ID、行政代码、城市名称、IP地址）
        :return: 
        """
        response = self.client.get(
            url=f"/tianqi/index?key={self.api_key}&city={city}&type=1"
        ).json()
        return response["result"]


if __name__ == '__main__':
    print(TianApi().get_rainbowFart())
